package yzm

import (
	"context"

	"web-ppt/internal/consts"
	"web-ppt/internal/logic/mail"
	"web-ppt/internal/logic/rands"
	"web-ppt/internal/logic/session"
)

type Yzm struct{}

func New() *Yzm {
	return &Yzm{}
}

func (y *Yzm) SetLogin(ctx context.Context) error {
	yzm := rands.New().RandString(6, "0123456789")
	err := mail.New().SendMail("fy@junzhe.net", "您的登陆验证码是:"+"<pre>"+yzm+"</pre>")
	if err != nil {
		return err
	}
	session.New().Set(ctx, consts.SessionLoginYzm, yzm)
	return nil
}
